//本解法的原理是路径逆反路程不变
#include <iostream>
using namespace std;

const int N = 510;

int n;
int a[N][N];
int f[N][N];

int main()
{
    freopen("cin.txt", "r", stdin);
    //底层就不会出界啦，这里也不用担心边缘值的问题啦
    cin >> n;
    for (int i = 1; i <= n; ++i) //第几层
        for (int j = 1; j <= i; ++j)
            cin >> a[i][j];
    for (int i = 1; i <= n; ++i)
        f[n][i] = a[n][i];           //最底层没得走
    for (int i = n - 1; i >= 1; --i) //从底层遍历
        for (int j = 1; j <= i; ++j)
            f[i][j] = max(f[i + 1][j] + a[i][j], f[i + 1][j + 1] + a[i][j]);
    cout << f[1][1]; //最后输出到顶端的最大值即可
    return 0;
}